package com.baosight.sczx.zm.ch.service;
import com.baosight.iplat4j.core.ei.EiBlock;
import com.baosight.iplat4j.core.ei.EiConstant;
import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.ep.ServiceEPBase;
import com.baosight.sczx.common.StaticBlocks;
import com.baosight.sczx.common.zm.basetools.StaticTools;
import com.baosight.sczx.common.zm.basetools.TablePk;
import com.baosight.sczx.zm.ch.domain.ZMCHWorkGroup;

/**
 * 班组管理
 */

public class ServiceZMCH50 extends ServiceEPBase {
	/**
	 * <p>Function: initLoad</p>
	 * <p>Description: 初始化</p> 
	 */
	@Override
	public EiInfo initLoad(EiInfo inInfo) {
		inInfo.addBlock(EiConstant.resultBlock).set("showCount", "true");//如果不加这个，翻页的统计和显示是错误的		
		EiInfo outInfo = this.query(inInfo);
		return outInfo;
	}
	
	/**
	 * 查询
	 */
	public EiInfo query(EiInfo inInfo) {
		String fdMiningId = (String)UserSession.getInSessionProperty("miningCode");
	    String fdDepartmentId = (String)UserSession.getInSessionProperty("orgCode");
	    
		StaticTools.setQueryParameters(inInfo, "fdMiningId", fdMiningId, true);
		StaticTools.setQueryParameters(inInfo, "fdDepartmentId", fdDepartmentId, true);
		
		EiInfo outInfo = super.query(inInfo, "ZMCHWorkGroup.query", new ZMCHWorkGroup());
		outInfo.addBlock(
				StaticBlocks.getBlockData("cmes.cd.businesstype", new String[] { "采煤", "掘进", "抽采", "机电", "运输", "通风", "安全", "其它" }, new String[] { "采煤", "掘进", "抽采", "机电", "运输", "通风", "安全", "其它" }, true));// 班組的工作类型
		outInfo.addBlock(StaticBlocks.getBlockData("cmes.cs.status", new String[] { "在用", "停用" }, new String[] { "在用", "停用" }, true));// 使用状态

		return outInfo;
	}
	
	/**
	 * 新增
	 */
	@Override
	public EiInfo insert(EiInfo inInfo) {	
		EiInfo out = new EiInfo();
		ZMCHWorkGroup _dom = new ZMCHWorkGroup();
		EiBlock eiBlock = inInfo.getBlock("result");
		eiBlock.setBlockMeta(_dom.eiMetadata);
		int rowcount = eiBlock.getRowCount();
		
		for (int i = 0; i < rowcount; i++) {
			_dom.fromMap(eiBlock.getRow(i));

			_dom.setFdStatus("草拟");
			_dom.setFdIsuseFlag("在用");
			_dom.setFdKeyId(TablePk.getInstance().getNextValue("T_CH_WORKGROUP"));//主键
			_dom.setFdMiningId(UserSession.getInSessionProperty("miningCode").toString());	//矿井id
			_dom.setFdMiningName(UserSession.getInSessionProperty("miningName").toString());// 矿井名称
			_dom.setFdDepartmentId(UserSession.getInSessionProperty("orgCode").toString());// 部门id
			_dom.setFdDepartmentName(UserSession.getInSessionProperty("orgName").toString());// 部门
			this.dao.insert("ZMCHWorkGroup.insert",_dom);
		}
		
		out = this.query(inInfo);
		out.setStatus(1);
		out.setMsg("操作" + rowcount + "记录成功");
		return out;
	}
	
	/**
	 * 修改
	 */
	@Override
	public EiInfo update(EiInfo inInfo) {
		
		EiInfo _temp = super.update(inInfo, "ZMCHWorkGroup.update");
		
		EiInfo out = new EiInfo();
		out = this.query(inInfo);
		out.setStatus(_temp.getStatus());
		out.setMsg(_temp.getMsg());
		
		return out;	
	}
	
	/**
	 * 删除
	 */
	@Override
	public EiInfo delete(EiInfo inInfo) {
		
		EiInfo _temp = super.delete(inInfo, "ZMCHWorkGroup.delete");
		
		EiInfo out = new EiInfo();
		out = this.query(inInfo);
		out.setStatus(_temp.getStatus());
		out.setMsg(_temp.getMsg());
		
		return out;	 
	}
} 